{%extend name="Public:layout"/%}

{%block name="title"%}
<h2 class="mb20">
    剧透管理
</h2>
{%/block%}

{%block name="contents"%}
<div class="heading clearfix">
    <div class="pull-right">
        <a href="{%:U('/admin/spoiler/save/')%}" class="btn mr5"><i class="icon i-add"></i>发布剧透</a>
    </div>
</div>
<table class="table table-listing table-hovered">
    <thead class="thead-gray">
    <tr>
        <th>ID</th>
        <th>杂志期号</th>
        <th>剧透标题</th>
        <th>排序</th>
        <th>图片</th>
        <th>APP内浏览量</th>
        <th>点赞</th>
        <th>评论</th>
        <th>状态</th>
        <th>管理</th>
    </tr>
    </thead>
    <tbody>
    {%notempty name="list"%}
    {%foreach name="list" item="vo" %}
    <tr>
        <td>{%$vo.spoiler_id%}</td>
        <td>{%$vo.issue_number%}</td>
        <td>{%$vo.spoiler_title%}</td>
        <th><input type="text" size="3" name="order_{%$vo.spoiler_id%}" value="{%$vo.order_by%}" onblur="ST.todo('changeOrder', '{%$vo.spoiler_id%}')" /></th>
        <td><img width="100" height="50" src="{%$vo.spoiler_img|httpThumb=0,100%}" /></td>
        <td><a href="{%:U('/admin/statisticview/getlist/')%}?type=3&id={%$vo.spoiler_id%}">{%$vo.views%}</a></td>
        <td><a href="{%:U('/admin/statisticpraise/getlist/')%}?type=3&id={%$vo.spoiler_id%}">{%$vo.praises%}</a></td>
        <td><a href="{%:U('/admin/statisticcomment/getlist/')%}?type=3&id={%$vo.spoiler_id%}">{%$vo.commentCount%}</a></td>
        <td>
            {%eq name="vo['status']" value="1"%}
            <font color="green">已上线</font>
            <a href="javascript:;" onclick="ST.todo('publish', '{%$vo.spoiler_id%}')">下线</a>
            {%else/%}
            待上线
            <a href="javascript:;" onclick="ST.todo('publish', '{%$vo.spoiler_id%}')">上线</a>
            {%gt name="vo['auto_publish_time']" value="0"%}
            <br/><font color="red">自动上线：{%$vo['auto_publish_time']|date='Y-m-d H:i',###%}</font>
            {%/gt%}
            {%/eq%}
        </td>
        <td>
            <a href="{%:U('/admin/spoiler/save/')%}?spoiler_id={%$vo.spoiler_id%}" class="mr5"><i class="icon i-edit"></i></a>
            <a href="javascript:;" onclick="ST.todo('del','{%$vo.spoiler_id%}')" class="mr5"><i class="icon i-del"></i></a>
            <a href="{%:U('/admin/comment/getlist')%}?type=3&id={%$vo.spoiler_id%}" class="mr5"><i class="icon i-visit"></i>评论记录</a>
            <a target="_blank" href="{%:U('/admin/public/preview/')%}?spoiler_id={%$vo.spoiler_id|num_encode%}"><i class="icon i-arrow-right"></i>预览</a>
        </td>
    </tr>
    {%/foreach%}
    {%/notempty%}
    </tbody>
</table>
<h2 class="m20"></h2>
<div class="paging">{%$page%}</div>
{%/block%}

{%block name="js"%}
<script>
    $.extend(ST.ACTION, {
        'change_order': "{%:U('/admin/spoiler/change_order')%}",
        'publish': "{%:U('/admin/spoiler/publish')%}",//删除目录action地址
        'del': "{%:U('/admin/spoiler/del')%}",//删除目录action地址
        'save': "{%:U('/admin/spoiler/save')%}"//添加目录弹窗地址
    });
    $.extend(ST, {
        changeOrder: function(id) {
            ST.execAJAX({
                url: ST.ACTION.change_order,     //服务端请求地址
                params: {spoiler_id: id, order_by: $('input[name=order_' + id +']').val()},
                hasconfirm: false,       //提交前是否显示确认框
                succFun: function (j) {  //成功后的回调方法：刷新页面
                }
            });
        },
        save: function (id) {
            ST.editBox(ST.ACTION.save + '/spoiler_id/' + id, {
                title: id == 0 ? '添加' : '修改',
                width: 960,
                height: '100%'
            });
        },
        publish: function (id) {
            ST.execAJAX({
                url: ST.ACTION.publish,     //服务端请求地址
                params: {spoiler_id: id},       //发送到服务端的参数（如：{myparam:1}）
                hasconfirm: false,
                succFun: function (j) {  //成功后的回调方法：刷新页面
                    if (!j) return;
                    if (j.data && j.data.url) {
                        location.href = j.data.url;
                    } else {
                        ST.reload();
                    }
                }
            });
        },
        del: function (id) {
            ST.execAJAX({
                url: ST.ACTION.del,     //服务端请求地址
                params: {spoiler_id: id},       //发送到服务端的参数（如：{myparam:1}）
                massage: '确定删除吗？',       //提示信息（仅hasconfirm为true时有用）
                hasconfirm: true,       //提交前是否显示确认框
                succFun: function (j) {  //成功后的回调方法：刷新页面
                    if (!j) return;
                    if (j.data && j.data.url) {
                        location.href = j.data.url;
                    } else {
                        ST.reload();
                    }
                }
            });
        },
        //批量删除
        delAll: function () {
            var ids = ST.getSelectedValue().join(',');
            if (!ids) {
                ST.tipMsg('请至少选择一项');
            } else {
                ST.del(ids);
            }
        },
        //获得选中值
        getSelectedValue: function () {
            var $options = $('.js-toggleall-target:checked'), arr = [];
            $options.each(function () {
                arr.push($(this).val());
            });
            return arr;
        }
    });
    ST.init();
</script>
{%/block%}